package woshiheima7;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.TreeSet;
//斗地主升级版
public class PokerDemo {
    public static void main(String[] args) {
        //创建hashmap集合对象
        HashMap<Integer,String> hm = new HashMap<Integer,String>();

        //创建ArrayList集合对象
        ArrayList<Integer> array = new ArrayList<Integer>();

        //从0开始往HashMap里面存储编号，并存储对应的牌，同时往ArrayList里面存编号；
        String [] colors ={"♢","♣","♤","♡"};
        String [] numbers = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
        //创建编号为0
        int index = 0;
        //双重循环打印出52张牌
         for (String number:numbers){
             for (String color:colors){
                 hm.put(index,number+color);//将编号和牌通过键和值存进HashMap集合
                 array.add(index);//将编号索引存进ArrayList集合
                 index++;
             }
         }
         hm.put(index,"小王");
         array.add(index);
         index++;
         hm.put(index,"大王");
         array.add(index);
         index++;
         //洗牌
        Collections.shuffle(array);
        //发牌 创建对象用于发牌后存牌的
        TreeSet<Integer> lqxSet = new TreeSet<Integer>();
        TreeSet<Integer> lySet = new TreeSet<Integer>();
        TreeSet<Integer> fqySet = new TreeSet<Integer>();
        TreeSet<Integer> dpSet = new TreeSet<Integer>();

        for (int i =0;i<array.size();i++){
            int x=array.get(i);//将编号给x
            if ( i>=array.size()-3){//最后三张牌给dpset
                dpSet.add(array.get(i));
            }else if (i%3==0){
                lqxSet.add(x);
            }else if (i%3==1){
                lySet.add(x);
            }else if (i%3==2){
                fqySet.add(x);
            }

        }

        //调用看牌方法
        lookpoker("林青霞",lqxSet,hm);
        lookpoker("刘岩",lySet,hm);
        lookpoker("风清扬",fqySet,hm);
        lookpoker("底牌",dpSet,hm);
    }
    //定义看牌方法
    public static void lookpoker(String name,TreeSet<Integer> ts,HashMap<Integer,String> hm){
        System.out.print(name+"名字是:");
        for (Integer key: ts){
            //将编号打印出来再通过Map集合来找对应的编号的值
            String poker = hm.get(key);//将值存进poker变量中以便操作
            System.out.print(poker);
        }
        System.out.println();
    }
}
